from direct.gui.DirectGui import DirectScrolledFrame
from Cube.gui.QSizer import ResizedCallBackSet, BoxSizer

DefaltParameter_ScrolledFrame = dict(
        scrollBarWidth = 0.04,
        borderWidth = (0,0),
        )

class QScrolledFrame():
    def __init__(self,
                 parent = None,
                 packObject = None,
                 fixVertical = False,
                 fixHorizontal = False,
                 param_ScrolledFrame = {}
                 ):
        paramIn_ScrolledFrame = DefaltParameter_ScrolledFrame.copy()
        paramIn_ScrolledFrame.update(param_ScrolledFrame)
        paramIn_ScrolledFrame["parent"] = parent
        myScrolledFrame = DirectScrolledFrame(**paramIn_ScrolledFrame)
        packObject.reparentTo(myScrolledFrame.getCanvas())

        if fixHorizontal: orient = BoxSizer.HORIZONTAL
        else: orient = BoxSizer.VERTICAL
        sizerMain = BoxSizer(orient)
        sizerMain.Add(myScrolledFrame, (not (fixVertical or fixHorizontal)) )
        sizerMain.Attach2Frame(self)
        ResizedCallBackSet(myScrolledFrame, self.ResizedCallBackHadle)

        self._QScrolledFrame = myScrolledFrame

    # override it
    def ResizedCallBackHadle(self):
        pass

    def destroy(self):
        self._QScrolledFrame.destroy()

